import java.util.ArrayList;
import java.util.List;
public class ComponentComposite extends  Component {
    private List<Component> childrenList = new ArrayList<Component>();

    public ComponentComposite(String componentName,String componentJob) {
        super(componentName,componentJob);
    }

    @Override
    public boolean addChild(Component child) {
        return this.childrenList.add(child);
    }

    @Override
    public boolean removeChild(Component child) {
        return this.childrenList.remove(child);
    }

    @Override
    public Component getChild(int childIndex) {
        return this.childrenList.get(childIndex);
    }

    @Override
    public void operation() {
        System.out.println("容器结点："+getComponentName()+" 执行工作："+getComponentJob());
        for( Component currentComponent : childrenList ){
            currentComponent.operation();
        }

    }
}
